package com.vectquant.lwwl_service01.controller;

import com.vectquant.lwwl_service01.dto.ChatRequest;
import com.vectquant.lwwl_service01.dto.ChatResponse;
import com.vectquant.lwwl_service01.model.ChatHistory;
import com.vectquant.lwwl_service01.service.AiChatService;
import org.springframework.web.bind.annotation.*;

/**
 * AI聊天控制器
 * 提供RESful API接口供前端调用
 * RestController 标识这是一个REST控制器
 * @RequestMapping 定义基础路径
 * @CrossOrigin允许跨域请求
 */
@RestController
@RequestMapping("/api/auth")
public class AiChatController {
    private final AiChatService aiChatService;
    public AiChatController(AiChatService aiChatService){
        this.aiChatService = aiChatService;
    }
/**
 * 与AI聊天接口
 * @param request聊天请求
 * @return AI回复
 */
    @PostMapping("/chat")
    public ChatResponse chat(@RequestBody ChatRequest request){
    return aiChatService.chatWithAI(request);
    }
    /**
     * 获取聊天历史接口
     * @param userId 用户ID
     * @retrun 聊天历史
     */
    @GetMapping("/history")
    public String getHistory(@RequestParam String userId){
        return aiChatService.getChatHistory(userId);
    }
    /**
     * 健康检查接口
     * @return 服务状态*/
    @GetMapping("/health")
    public String healthCheck(){
        return "AI Chat Service is running";
    }
}
